<template>
  <el-form ref="form" :model="notice" label-width="80px">
    <el-form-item label="公告名称">
      <el-input v-model="notice.title"></el-input>
    </el-form-item>
    <el-form-item label="公告内容">
      <el-input
        type="textarea"
        v-model="notice.content"
        style="width: 400px"
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即添加</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "AddGongGao",
  data() {
    return {
      notice: {
        title: "",
        content: "",
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
      if (this.notice.title != "" && this.notice.content != "") {
        const employeeId = window.sessionStorage.getItem("employeeId");
        this.$request
          .post("notice/insert", {
            title: this.notice.title,
            content: this.notice.content,
            employeeId: employeeId,
          })
          .then((res) => {
            if (res.data.obj) {
              this.$message.success("添加成功！");
              this.notice.title = "";
              this.notice.content = "";
            } else {
              this.$message.warning("添加失败！");
            }
          });
      } else {
        this.$message.error("请输入完整再次尝试！");
      }
    },
  },
};
</script>

<style scoped>
.el-input {
  width: 400px;
}
</style>